package com.dragon.modules.yuegou.utils;

import com.dragon.modules.media.workbook.DefaultWorkbookMapper;
import com.dragon.modules.media.workbook.WorkbookMapper;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;

public class ReadExcelHelper {


    public <T> T readExcel(MultipartFile file, Class<T> type) {
        try (InputStream input = file.getInputStream()) {
            WorkbookMapper workbookMapper = new DefaultWorkbookMapper();
            return workbookMapper.deserialize(type,input);
        } catch (IOException e) {
            throw new UncheckedIOException("读取Excel：" + file.getName(), e);
        }

    }
}
